package com.ysy.logistics.myenum;

import com.alibaba.fastjson2.annotation.JSONType;
import com.fasterxml.jackson.annotation.JsonFormat;



/**
 * @author 姚斯羽
 * @date 2025/4/16 13:59
 * @description: 设备类型
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum DeviceType {
    WD("温度设备",0,"°C"),
    SD("湿度设备",1,"%RH");
    private String name;
    private Integer code;
    private String unit;

    public static String getUnitByCode(Integer code) {
        for (DeviceType deviceType : DeviceType.values()) {
            if (deviceType.getCode().equals(code)) {
                return deviceType.getUnit();
            }
        }
        return null;
    }


    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getUnit() {
        return unit;
    }

    DeviceType(String name, Integer code, String unit ) {
        this.code = code;
        this.name = name;
        this.unit = unit;
    }

    //根据Code判断是否存在
    public static boolean isExist(Integer code) {
        for (DeviceType deviceType : DeviceType.values()) {
            if (deviceType.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }

    //根据Code获取name
    public static String getNameByCode(Integer code) {
        for (DeviceType deviceType : DeviceType.values()) {
            if (deviceType.getCode().equals(code)) {
                return deviceType.getName();
            }
        }
        return null;
    }


}
